package com.example.utils;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;



public class JdbcUtils {
    public static String url = null;
    public static String user = null;
    public static String password = null;
    static {
        try {
            InputStream inStream = JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties");
            Properties properties = new Properties();
            properties.load(inStream);
            url = properties.getProperty("sql");
            user = properties.getProperty("username");
            password = properties.getProperty("password");
            System.out.println(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        System.out.println("SQL已连接...");
        return DriverManager.getConnection(url, user, password);
    }

    public static void release(Connection conn, PreparedStatement ppst, ResultSet rst) throws SQLException{
        conn.close();
        ppst.close();
        rst.close();
        System.out.println("SQL已断开...");
    }

    public static void release(Connection conn, PreparedStatement ppst) throws SQLException{
        conn.close();
        ppst.close();
        System.out.println("SQL已断开...");
    }
}
